package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * ==spring.xml
 */
@Configuration
public class WebMvConfig implements WebMvcConfigurer {
    /**
     * 跨域;
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/api/**").allowedOrigins("*").allowedHeaders("*").allowCredentials(false).maxAge(1800);
    }

    /**
     * 静态资源配置;(配置虚拟路径)
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/images/**").addResourceLocations("file:E:\\Test\\");
    }
}
